<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="btn">gogogo</button>

<script>
    function sendAjax(url){
        return new Promise(((resolve, reject) => {
            const xhr = new XMLHttpRequest();
            xhr.open("GET",url);
            xhr.send();
            //处理
            xhr.onreadystatechange = function (){
                if(xhr.readyState ===4){
                    //成功
                    if(xhr.status>=200&&xhr.status<=300){
                        resolve(xhr.response);
                    }else {
                        //失败
                        reject(xhr.status);
                    }
                }
            }
        }))
    }
    let btn = document.querySelector('#btn')
    btn.addEventListener('click',async function (){
        let duanzi = await sendAjax('https://api.apiopen.top/getJoke');
        console.log(duanzi)
    })
</script>
</body>
</html>
